package com.baicaoyuan.web.common;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.core.util.MultivaluedMapImpl;

import javax.ws.rs.core.MediaType;

/**
 * 功能描述：短信服务
 *
 * @author 罗富祥
 *         创建时间： 2017/11/24
 *         版权：百草园电子商务
 */
public class SmsService {

    public static String do_send_sms(String phoneNum, String message) {
        Client client = Client.create();
        client.addFilter(new HTTPBasicAuthFilter("api", AppInfo.SMS_API_KEY));
        WebResource webResource = client.resource(AppInfo.SMS_RESOURCE);
        MultivaluedMapImpl formData = new MultivaluedMapImpl();
        formData.add("mobile", phoneNum);
        formData.add("message", message);
        ClientResponse response =
                webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
        String textEntity = response.getEntity(String.class);
        return textEntity;
    }
}
